package com.fc.app.fcapp.pages.linechart;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Build;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.fc.app.fcapp.CoreFuncKt;
import com.fc.app.fcapp.R;
import com.fc.library.fresco.Util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

/**
 * Created by Administrator on 2017/12/6.
 */

public class ChartMainLayout extends FrameLayout {
    private Context mContext;
    private FrameLayout.LayoutParams params;
    private VerticalLine verticalLine;

    private Button button, button2;


    public ChartMainLayout(@NonNull Context context) {
        super(context);
        setBackgroundColor(Color.GRAY);
        mContext = context;
        initView();
    }



    private void initView() {
        button = new Button(mContext);
        button.setText("画图");
        button.setOnClickListener(onClickListener);
        params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        addView(button, params);

        button2 = new Button(mContext);
        button2.setText("压缩");
        button2.setOnClickListener(onClickListener);
        params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.leftMargin = Util.Div(200);
        addView(button2, params);

        ImageView imageView = new ImageView(mContext);
//        imageView.setBackgroundColor(Color.WHITE);
        imageView.setBackgroundResource(R.drawable.user_icon_ring);
        params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.leftMargin = Util.Div(400);
        addView(imageView, params);



        verticalLine = new VerticalLine(mContext);
        params = new FrameLayout.LayoutParams(Util.Div(30), Util.Div(545));
        params.topMargin = Util.Div(100);
        params.leftMargin = Util.Div(200);
        addView(verticalLine, params);

        PathView pathView = new PathView(mContext);
        addView(pathView);



    }





    private List<Point> pointList;

    private void drawLine() {

        pointList = new ArrayList<>();
        Point point = new Point(200, 400);
        pointList.add(point);
        point = new Point(200 + 150, 300);
        pointList.add(point);
        point = new Point(200 + 150 + 150, 200);
        pointList.add(point);

    }

    public class Point {
        public int x;
        public int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

    }


    private ScheduledExecutorService scheduledExecutorService;

    private OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {

            if (v.equals(button)) {

//                checkView.check();


                drawLine();
                scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
                scheduledExecutorService.scheduleWithFixedDelay(new DrawTask(), 0, 1, TimeUnit.SECONDS);


            }


        }
    };


    private class DrawTask implements Runnable {

        @Override
        public void run() {
            CoreFuncKt.runOnUiThread(new Function0<Unit>() {
                @Override
                public Unit invoke() {

                    return null;
                }
            });

        }
    }


}
